<template>
      <!-- 搜索表单 -->
  <div style="width: 100%;height: 100%">
      <iframe ref="iframeContainer" id="iframeEle"
              :style="{ width:'100%',height:iframeHeight}"
              frameborder="0"
              :src="reporturl">
      </iframe>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import setting from "@/config/setting";

export default {
  name: 'ExamPoOrder',
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表格数据接口
      url: '/kdlpurchasein/index',
      iframeHeight:'600px',
      reporturl:'',
      // 表格列配置
      columns: [
        {
          columnKey: 'index',
          type: 'index',
          width: 45,
          align: 'center',
          fixed: "left"
        },
        {
          prop: 'grdate',
          label: '单据日期',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'vendorpo',
          label: '订单号',
          showOverflowTooltip: true,
          minWidth: 120,
          align: 'center'
        },
        {
          prop: 'billtypename',
          label: '单据类型',
          showOverflowTooltip: true,
          minWidth: 180,
          align: 'left'
        },
        {
          prop: 'orgname',
          label: '事业部',
          showOverflowTooltip: true,
          minWidth: 120,
          align: 'center'
        },
        {
          prop: 'vendorcode',
          label: '供应商代码',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'vendorname',
          label: '供应商名称',
          showOverflowTooltip: true,
          minWidth: 180,
          align: 'center'
        },
        {
          prop: 'statusdesc',
          label: '状态',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'cahpo',
          label: 'KDL物料凭证号',
          showOverflowTooltip: true,
          minWidth: 130,
          align: 'center'
        },
        {
          prop: 'principalid',
          label: '药厂代码',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'companycode',
          label: '组织',
          showOverflowTooltip: true,
          minWidth: 60,
          align: 'center'
        },
        {
          prop: 'createTime',
          label: '创建时间',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 160,
          align: 'center',
          formatter: (row, column, cellValue) => {
            return this.$util.toDateString(cellValue);
          }
        },
        {
          prop: 'updateTime',
          label: '更新时间',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 160,
          align: 'center',
          formatter: (row, column, cellValue) => {
            return this.$util.toDateString(cellValue);
          }
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 150,
          align: 'center',
          resizable: false,
          slot: 'action',
          fixed: "right"
        }
      ],
      columnsInspect:[
        {
          columnKey: 'index',
          type: 'index',
          width: 45,
          align: 'center',
          fixed: "left"
        },
        {
          prop: 'inspectionlot',
          label: '质检检验批',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'cmaterialvid',
          label: '药品编码',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'comdescription',
          label: '通用名',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'left'
        },
        {
          prop: 'nnum',
          label: '数量',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'salesunit',
          label: '单位',
          showOverflowTooltip: true,
          minWidth: 60,
          align: 'center'
        },
        {
          prop: 'vlotno',
          label: '批号',
          showOverflowTooltip: true,
          minWidth: 130,
          align: 'center'
        },
        {
          prop: 'vlotnoDprodate',
          label: '生产日期',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'vlotnoVinvaliddate',
          label: '有效期',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'boxflag',
          label: '箱型',
          showOverflowTooltip: true,
          minWidth: 60,
          align: 'center'
        },
        {
          prop: 'boxno',
          label: '箱号',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'umrez',
          label: '箱规',
          showOverflowTooltip: true,
          minWidth: 60,
          align: 'center'
        },
        {
          prop: 'cwarehouseid',
          label: '仓库',
          showOverflowTooltip: true,
          minWidth: 60,
          align: 'center'
        },
        {
          prop: 'bindesc',
          label: '仓库名称',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'materialgroup',
          label: '类别',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'left'
        },
        {
          prop: 'lregistno',
          label: '批准文号',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'left'
        },
        {
          prop: 'registrationfilingapplicantname',
          label: '上市许可持有人',
          showOverflowTooltip: true,
          minWidth: 180,
          align: 'left'
        },
        {
          prop: 'materialform',
          label: '剂型',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'left'
        },
        {
          prop: 'manufacturername',
          label: '生产企业',
          showOverflowTooltip: true,
          minWidth: 180,
          align: 'left'
        },
        {
          prop: 'cstateid',
          label: '库存状态',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'inspectionidname1',
          label: '检验人员1',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'inspectiondate1',
          label: '检验日期1',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'inspectionidname2',
          label: '检验人员2',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'inspectiondate2',
          label: '检验日期2',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'status',
          label: '状态',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'pkBatchcode',
          label: '批次号',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'cfirstbillbid',
          label: '药厂主键',
          showOverflowTooltip: true,
          minWidth: 180,
          align: 'center'
        },

      ],
      // 表格搜索条件
      where: {riqiBegin:this.getFromDate(),riqiEnd:new Date()},
      selectedRows:0,
      // 表格选中数据
      selection: [],
      selectionInspect: [],
      inspectList:[],
      ssbkList:[],
      billtypeList:[],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      showLog: false,
    };
  },
  mounted() {
    this.adjustIframeSize();
    window.addEventListener('resize', this.adjustIframeSize);
    console.log(this.$route.meta);
    this.reporturl = setting.fineReportURL+ this.$route.meta.reporturl;
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.adjustIframeSize);
  },
  watch:{
    $route(to){
        this.reporturl = setting.fineReportURL+ to.meta.reporturl;
        //this.$refs.iframeContainer.src = this.reporturl;
        console.log(this.reporturl);
    }
  },
  methods: {
    adjustIframeSize(){
      let containerWidth=  window.parent.document.documentElement.offsetHeight - 105;
      // if(containerWidth>630) {
      //   containerWidth=620;
      // }
      this.iframeHeight = `${containerWidth}px`;
      //console.log(this.iframeHeight);
    },
    async loadInspectResult(row){
      var res = await this.$http.get('/kdlpurchasein/inspectresult?pid='+row.id);
      if(res.status==200)
      {
        this.inspectList = res.data.data;
      }
    },
    async getSsbkList(){
      var res = await this.$http.get('/dictdata/index?dictId=19&page=1&limit=1000');
      if(res.status==200)
      {
        this.ssbkList = res.data.data.records;
      }

    },
    async getBilltypeList(){
      var res = await this.$http.get('/kdl/ncbilltype?orgcode='+this.where.companycode+'&bill=PO');
      if(res.status==200)
      {
        this.billtypeList = res.data.data;
      }

    },
    getFromDate() {
      const timeOne = new Date()
      const year = timeOne.getFullYear()
      let month = timeOne.getMonth()
      let day = 1
      //month = month < 10 ? '0' + month : month
      //day = day < 10 ? '0' + day : day
      ///const NOW_MONTHS_AGO = `${year}-${month}-${day}`
      return new Date(year,month,day);
    },
    /* 刷新表格 */
    reload() {
      this.inspectList=[];
      this.$refs.table.reload({where: this.where});
    },
    syncPurchase(){
      const loading = this.$loading({lock: true});
      this.$http.post('/kdlpurchasein/syncpurchase', {}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });

    },
    /* 重置搜索 */
    reset() {
      this.where = {riqiBegin:this.getFromDate(),riqiEnd:new Date()};
      this.reload();
    },
    openLog(row){
      this.current = row;
      this.current.chukNo = row.vendorpo;
      //console.log(this.current);
      this.showLog = true;
    },
    /* 显示编辑 */
    openEdit(row) {
      this.$confirm('确定要将选中的采购质检记录回写至NC吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({lock: true});
        this.$http.post('/kdl/submitInspect/'+ row.id).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            //this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
      // this.current = row;
      // this.showEdit = true;
    },
    /* 删除 */
    remove(row) {
      const loading = this.$loading({lock: true});
      this.$http.delete('/kdlpurchasein/delete/'+row.id).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    /* 批量删除 */
    removeBatch() {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      this.$confirm('确定要删除选中的采购质检订单回传吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({lock: true});
        this.$http.delete('/kdlpurchasein/delete', {id: this.selection.map(d => d.id)}).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
    },
  }
}
</script>

<style scoped>
.el-form{
}
.ele-form-search{
  margin-top: -15px ;
  margin-bottom: -5px;
}
.el-form-item {
  margin-bottom: -5px !important;
}
</style>
